package top.ywlog.permission.common.response;

import lombok.Getter;
import lombok.Setter;

import java.util.Objects;

/**
 * @author Durian
 * @date: 2020/10/17 21:00
 * @description: 数据返回封装
 */
@Getter
@Setter
public class Result
{
    private Integer code;

    private String msg;

    private Object data;

    private Result(ResultCode resultCode)
    {
        this.code = resultCode.getCode();
        this.msg = resultCode.getMsg();
    }

    private Result(ResultCode resultCode, Object data)
    {
        this.code = resultCode.getCode();
        this.msg = resultCode.getMsg();
        this.data = data;
    }


    private Result(Integer code, String msg)
    {
        this.code = code;
        this.msg = msg;
    }

    public static Result fail(Integer code, String msg)
    {
        return new Result(code, msg);
    }

    public static Result success(Object data)
    {
        return new Result(ResultCode.SUCCESS, data);
    }

    public static Result success()
    {
        return new Result(ResultCode.SUCCESS);
    }

    public static Result fail(ResultCode resultCode)
    {
        return new Result(resultCode);
    }

    public static Result fail(ResultCode resultCode, Object data)
    {
        return new Result(resultCode, data);
    }
}
